<template>
  <TableCom :columns="column.columns" :options="subOptions" @getList="getDetail"/>
</template>

<script>
  export default {
    name:'ColumnSubtable',
    dicts:[],
    props:{
      scope:Object,
      column:{
        type:Object
      }
    },
    data(){
      return {
        subOptions:{
          pageNum: 1,
          pageSize: 10,
          loading:false,
          total:0,
          data:[]
        }
      }
    },
    mounted(){
      this.getResult();
    },
    methods:{
      getResult(){
        let getList = this.column.getList;
        let row = this.scope.row;
        let promise = new Promise((resolve)=>{
          if(row._result){
            resolve(row._result)
          }
          //
          if(getList){
            resolve(getList(row))
          }
          //
          if(row.child){
            resolve({data:row.child})
          }
        })
        //
        this.subOptions.loading = true;
        promise
          .then((res = {})=>{
            row._result = res;
            Object.assign(this.subOptions,res);
          }).finally(()=>{
            this.subOptions.loading = false;
          })
      }
    }
  }
</script>
